package com.msb.mall.mallsearch.thread;

/**
 * @Auther: huangxiaode
 * @Date: 2023/3/11 0011 - 03 - 11 - 19:50
 * @Description: com.msb.mall.mallsearch.thread
 * @version: 1.0
 */

import io.netty.util.concurrent.DefaultThreadFactory;

import java.util.concurrent.*;

/**
 * CompletetablefutureDemo
 */
public class CompletetablefutureDemo {

    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(
            5,
            50,
            10,
            TimeUnit.SECONDS,
            new LinkedBlockingDeque<>(100),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.AbortPolicy());
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main ---- 线程开始了 .....");
        // 获取Completetablefuture对象
        CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
            System.out.println("线程开始了 .........");
            int i = 100 / 50;
            System.out.println("线程结束了 .........");
        },executor);
        System.out.println("main ---- 线程结束了 .....");

        CompletableFuture<Integer> future1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("线程开始了 .........");
            int i = 100 / 50;
            System.out.println("线程结束了 .........");
            return i;
        }, executor);
        System.out.println("获取的线程的返回结果是 : " + future1.get());
    }
}
